import json
import cv2

 
image_annotation_path = '/data/train/image_annotation/050960/0.json'
imge_path = '/data/train/image/050960/0.jpg'
color = {0:(220,20,60), 1:(75,0,130), 2:(0,0,255), 3:(46,139,87), 4:(255,255,0), 5:(105,105,105), 6:(244,164,96)}
font = cv2.FONT_HERSHEY_SIMPLEX

img_tran = cv2.imread(imge_path)

with open(image_annotation_path,'r') as load_f:
    load_dict = json.load(load_f)

color_control = 0

for i in load_dict['annotations']:
    xmin, ymin, xmax, ymax = i['box']
    label = i['label']
    cv2.rectangle(img_tran, (xmin, ymin), (xmax, ymax), color[color_control], 3)
    cv2.putText(img_tran, label, (xmin, ymin), font, 1, color[color_control], 2)
    color_control += 1

save_path = '/mnt/dbvalidation/bbox_pic/' + imge_path[-5] + '_' + imge_path[-5:]
cv2.imwrite(save_path, img_tran)

